﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Xml.Serialization;
using BaseDll;
using UserCtrl;


namespace UserData
{
    public class UserTest
    {
        public static TestResultClass[] TestResultAB = new TestResultClass[1] { new TestResultClass() };
        public static ManualResetEvent[] WaitTableRun = new ManualResetEvent[] { new ManualResetEvent(false), new ManualResetEvent(false), new ManualResetEvent(false), new ManualResetEvent(false), new ManualResetEvent(false) };
        public static ProductCheckResult[] ProductCheckResultAB = new ProductCheckResult[] { new ProductCheckResult(), new ProductCheckResult(), new ProductCheckResult(), new ProductCheckResult() };
        public static ProductInfo[] ProductCount = new ProductInfo[7] { new ProductInfo(), new ProductInfo(), new ProductInfo(), new ProductInfo(), new ProductInfo(), new ProductInfo(), new ProductInfo() };
        //public static ProductInfo[] ProductCount = new ProductInfo[] { new ProductInfo(), new ProductInfo(), new ProductInfo(), new ProductInfo() };
        public static TestTime TestTimeInfo = new TestTime();
        public static FailResult FailResultAB = new FailResult();
        public static CTTest[] CTTestAB = new CTTest[] { new CTTest(), new CTTest(), new CTTest(), new CTTest() };
        public static string algType = "";//算法类型，chart 和coll 电控运动初始化会不一样
        public static bool ContiuneWhlie = true;//用于关闭软件中的while循环
        public static LogClass LogHelper = new LogClass();
        //public static List<CalibrationDisp> DispCalibrationAB = new List<CalibrationDisp>();
        public static string Batch = "批次1";
        public static string Model = "机型1";
        public static bool Print =false;
    }
    public class ProductInfo
    {
        public double UPH { get; set; }
        public int OK { get; set; }
        //public double PencentAll { get; set; }
        public double Pencent { get; set; }

        public int NG { get; set; }

        //public int CurrentFail { get; set; }
        //public int PlayFail { get; set; }
        //public int OCFail { get; set; }
        //public int SFRFail { get; set; }
        //public int FOVFail { get; set; }
        //public int ColorFail { get; set; }
        //public int GrayFail { get; set; }
        //public int ParticleFail { get; set; }
        //public int BlemishFail { get; set; }
        //public int LensShedingFail { get; set; }
        //public int WBFail { get; set; }
        //public int HotPixelFail { get; set; }
        //public int PSNRFail { get; set; }
        public int Total { get; set; }
        [XmlIgnore]
        public double PencentCTAll { get; set; }
        [XmlIgnore]
        public DateTime StarCTTime { get; set; }
        [XmlIgnore]
        public DateTime EndCTTime { get; set; }
        [XmlIgnore]
        public double CountCTAll { get; set; } = 0;
        [XmlIgnore]
        public double CountCTTime { get; set; } = 0;
    }
    public class ProductInfoFile
    {
        public static bool ReadCT(string path)
        {
            UserTest.ProductCount = (ProductInfo[])AccessXmlSerializer.XmlToObject(path, typeof(ProductInfo[]));
            if (UserTest.ProductCount == null)
            {
                return false;
            }
            return true;
        }
        public static void SaveCT(string path)
        {
            AccessXmlSerializer.ObjectToXml(path, UserTest.ProductCount);
        }
    }
    //csv



    public class TestResult
    {
        #region 私有变量
        private double _testTime = 0;
        #endregion
        /// <summary>
        /// 机型
        /// </summary>
        public string Model { get { return UserTest.Model; } }
        /// <summary>
        /// 批次
        /// </summary>
        public string Batch { get { return UserTest.Batch; } }
        /// <summary>
        /// SN
        /// </summary>
        public string SerialNumber { get; set; } = $"Time_{DateTime.Now.ToString("yyyyMMdd_HHmmssfff")}";
        public string SocketerNumber { get; set; }
        /// <summary>
        /// 测试开始时间
        /// </summary>
        public DateTime StarTime { get; set; }
        /// <summary>
        /// 测试结束时间
        /// </summary>
        public DateTime EndTime { get; set; }
        /// <summary>
        /// 测试时间
        /// </summary>      
        public double TestTime { get { return Math.Round(_testTime, 2); } set { _testTime = value; } }
        /// <summary>
        /// 测试结果
        /// </summary>
        public bool Result { get; set; }
        public WorkStep Workstep { get; set; } = WorkStep.NG;
        /// <summary>
        /// 失败步骤
        /// </summary>
        public string FailStep { get; set; } = "PASS";

        public bool Play { get; set; }
        public bool CurrentResult { get; set; }
        public double Current { get; set; }
        #region 色差灰阶
        /// <summary>
        /// 色差测试
        /// </summary>
        public bool ColorTestResult { get; set; }

        public double ColorDeltaC1 { get; set; }
        public double ColorDeltaC2 { get; set; }
        public double ColorDeltaC3 { get; set; }
        public double ColorDeltaC4 { get; set; }
        public double ColorDeltaC5 { get; set; }
        public double ColorDeltaC6 { get; set; }
        public double ColorDeltaE1 { get; set; }
        public double ColorDeltaE2 { get; set; }
        public double ColorDeltaE3 { get; set; }
        public double ColorDeltaE4 { get; set; }
        public double ColorDeltaE5 { get; set; }
        public double ColorDeltaE6 { get; set; }
        public bool GrayTestResult { get; set; }
        public double GrayDelta1 { get; set; }
        public double GrayDelta2 { get; set; }
        public double GrayDelta3 { get; set; }
        public double GrayDelta4 { get; set; }
        public double GrayDelta5 { get; set; }
        public double GrayDelta6 { get; set; }
        #endregion

        #region 白场测试 
        /// <summary>
        /// Blemish结果
        /// </summary>
        public bool BlemishTestResult { get; set; }
        /// <summary>
        /// Blemish失败个数
        /// </summary>
        public int BlemishTestCount { get; set; }
        /// <summary>
        /// Paticle结果
        /// </summary>
        public bool PaticleTestResult { get; set; }
        /// <summary>
        /// Paticle 多点失败个数
        /// </summary>
        public int PaticleTestBigCount { get; set; }
        /// <summary>
        /// Paticle 两个点失败个数
        /// </summary>
        public int PaticleTestDobCount { get; set; }
        /// <summary>
        /// Paticle 单个点失败个数
        /// </summary>
        public int PaticleTestSigCount { get; set; }
        /// <summary>
        /// WhiteBlance 结果
        /// </summary>
        public bool WhiteBlanceResult { get; set; }
        /// <summary>
        /// WhiteBlance R/G通道对比结果
        /// </summary>
        public double WhiteBlance_RG { get; set; }
        /// <summary>
        /// WhiteBlance B/G通道对比结果
        /// </summary>
        public double WhiteBlance_BG { get; set; }
        /// <summary>
        /// WhiteBlance R通道结果
        /// </summary>
        public double WhiteBlance_R { get; set; }
        /// <summary>
        /// WhiteBlance G通道结果
        /// </summary>
        public double WhiteBlance_G { get; set; }
        /// <summary>
        /// WhiteBlance B通道结果
        /// </summary>
        public double WhiteBlance_B { get; set; }
        /// <summary>
        /// LensShading 结果
        /// </summary>
        public bool LensShadingResult { get; set; }
        /// <summary>
        /// LensShading 最大减去最小差值
        /// </summary>
        public double LensShadingDelta { get; set; }
        /// <summary>
        /// LensShading 左上值
        /// </summary>
        public double LensShading_UL { get; set; }
        /// <summary>
        /// LensShading 右上值
        /// </summary>
        public double LensShading_UR { get; set; }
        /// <summary>
        /// LensShading 左下值
        /// </summary>
        public double LensShading_LL { get; set; }
        /// <summary>
        /// LensShading 右下值
        /// </summary>
        public double LensShading_LR { get; set; }
        #endregion
        #region chart
        /// <summary>
        /// OC结果
        /// </summary>
        public bool OCTestResult { get; set; }
        /// <summary>
        /// OC_X方向偏差
        /// </summary>
        public double OCTestDelX { get; set; }
        /// <summary>
        /// OC_Y方向偏差
        /// </summary>
        public double OCTestDelY { get; set; }

        /// <summary>
        /// FOV结果
        /// </summary>
        public bool FOVTestResult { get; set; }
        /// <summary>
        ///  FOV斜边方向偏差
        /// </summary>
       // public double FOVTestD { get; set; }
        /// <summary>
        ///  FOV H方向偏差
        /// </summary>
        public double FOVTestH { get; set; }
        /// <summary>
        ///  FOV V方向偏差
        /// </summary>
        public double FOVTestV { get; set; }
        /// <summary>
        /// SFR结果
        /// </summary>
        public bool SFRTestResult { get; set; }
        /// <summary>
        ///  SFR 中心值
        /// </summary>
        public double SFRCenter { get; set; }
        /// <summary>
        ///  SFR 左上值
        /// </summary>
        public double SFR_UL { get; set; }
        /// <summary>
        /// SFR 右上值
        /// </summary>
        public double SFR_UR { get; set; }
        /// <summary>
        ///  SFR 左下值
        /// </summary>
        public double SFR_DL { get; set; }
        /// <summary>
        ///  SFR 右下值
        /// </summary>
        public double SFR_DR { get; set; }
        /// <summary>
        ///  SFR 中心值
        /// </summary>
        public double SFRCenter50 { get; set; }
        /// <summary>
        ///  SFR 左上值
        /// </summary>
        public double SFR_UL50 { get; set; }
        /// <summary>
        /// SFR 右上值
        /// </summary>
        public double SFR_UR50 { get; set; }
        /// <summary>
        ///  SFR 左下值
        /// </summary>
        public double SFR_DL50 { get; set; }
        /// <summary>
        ///  SFR 右下值
        /// </summary>
        public double SFR_DR50 { get; set; }
        #endregion
        #region 黑场
        /// <summary>
        /// HotPixel 结果
        /// </summary>
        public bool HotPixelTestResult { get; set; }
        /// <summary>
        /// HotPixel 多点失败个数
        /// </summary>
        public int HotPixelTestBigCount { get; set; }
        /// <summary>
        /// HotPixel 两个点失败个数
        /// </summary>
        public int HotPixelTestDobCount { get; set; }
        /// <summary>
        /// HotPixel 单个点失败个数
        /// </summary>
        public int HotPixelTestSigCount { get; set; }
        /// <summary>
        /// 图像信噪比PSNR
        /// </summary>
        public bool PSNRResult { get; set; }
        /// <summary>
        /// 图像信噪比PSNR
        /// </summary>
        public double PSNR { get; set; }

        public static implicit operator TestResult(TestResultClass v)
        {
            throw new NotImplementedException();
        }
        #endregion
    }
    public class ProductCheckResult
    {
        /// <summary>
        /// SN
        /// </summary>
        public string SerialNumber { get; set; } = "NOSN";
        /// <summary>
        /// 产品
        /// </summary>
        public string Product { get; set; }
        /// <summary>
        /// 测试开始时间
        /// </summary>
        public DateTime StarTime { get; set; }
        /// <summary>
        /// 测试结束时间
        /// </summary>
        public DateTime EndTime { get; set; }
        /// <summary>
        /// 测试时间
        /// </summary>
        public double TestTime { get; set; }
        /// <summary>
        /// 测试结果
        /// </summary>
        public bool Result { get; set; }

        //sfr 打印UV前四周加中心
        public double CheckSFR_CT_Value { get; set; }
        public double CheckSFR_UL_Value { get; set; }
        public double CheckSFR_UR_Value { get; set; }
        public double CheckSFR_DL_Value { get; set; }
        public double CheckSFR_DR_Value { get; set; }
        public double CheckSFRCenterDel { get; set; }
        public double CheckSFRCornerDel { get; set; }
        public double CheckOC_X { get; set; }
        public double CheckOC_Y { get; set; }
    }
    public class TestTime
    {
        public DateTime AAbegin { get; set; }
        public DateTime AAend { get; set; }
        public double AATime { get; set; }
        public double DispTime { get; set; }
        public double PlasmaTime { get; set; }
        public double Center_1 { get; set; }
        public double Center_2 { get; set; }
        public double Center_3 { get; set; }
        public double UVTime { get; set; }
        public double TF_1 { get; set; }
        public double TF_2 { get; set; }
        public double Tilt_1 { get; set; }
        public double Tilt_2 { get; set; }
        public DateTime Center_1_Begin { get; set; }
        public DateTime Center_2_Begin { get; set; }
        public DateTime Center_3_Begin { get; set; }
        public DateTime UVTime_Begin { get; set; }
        public DateTime TF_1_Begin { get; set; }
        public DateTime TF_2_Begin { get; set; }
        public DateTime Tilt_1_Begin { get; set; }
        public DateTime Tilt_2_Begin { get; set; }
        public DateTime PlasmaBegin { get; set; }
        public DateTime PlasmaEnd { get; set; }
        public DateTime DispBegin { get; set; }
        public DateTime DispEnd { get; set; }
    }
    public class FailResult
    {
        public bool Play { get; set; } = true;
        public bool OC { get; set; } = true;
        public bool SFR { get; set; } = true;
        public bool Tilt { get; set; } = true;

    }
    public class CTTest
    {
        public bool Star { get; set; } = false;
        public bool End { get; set; } = false;
        public bool Show { get; set; } = false;
    }
    public enum WorkStep
    {
        Star,
        色差测试,
        白场测试,
        SFR测试,
        黑场测试,
        结束,
        OK,
        NG,
        清料,

    }





}


